# 在使用会话时，它在内部引用 Connection，并使用 Connection 发出 SQL。
from sqlalchemy import text
from sqlalchemy.orm import Session
from sync.db import mysql_engine

with Session(mysql_engine) as session:
    result = session.execute(
        text("UPDATE some_table SET y=:y WHERE x=:x"),
        [{"x": 2, "y": 22}, {"x": 1, "y": 11}],
    )
    session.commit()

stmt = text("SELECT x, y FROM some_table WHERE y > :y ORDER BY x, y")
with Session(mysql_engine) as session:
    result = session.execute(stmt, {"y": 0})
    for row in result:
        print(f"x: {row.x}  y: {row.y}")
